package com.lhh.userservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhh.springcommon.annotation.WebLog;
import com.lhh.springcommon.annotation.WithRequestId;
import com.lhh.springcommon.entity.History;
import com.lhh.springcommon.entity.vo.VideoVO;
import com.lhh.springcommon.utils.PageQuery;
import com.lhh.springcommon.utils.Response;
import com.lhh.userservice.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 历史记录
 * @author 李厚航
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/history")
public class    HistoryController {


    private final UserHistoryService userHistoryService;


    @Autowired
    public HistoryController(UserHistoryService userHistoryService) {
        this.userHistoryService = userHistoryService;
    }

    /**
     * 分页查询历史记录
     * @return history集合
     */
    @GetMapping("/queryHistoryVideoVO")
    @WithRequestId
    @WebLog
    public Response<Page<VideoVO>> queryHistoryVideoVO(@RequestParam("page") Integer page,
                                                       @RequestParam("pageSize") Integer pageSize,
                                                       @RequestParam("uid") Integer uid) {
        return Response.success(userHistoryService.queryPageHistory(page, pageSize, uid));
    }

    /**
     * 添加历史记录
     * @param history 历史记录信息
     * @return 历史记录信息
     */
    @PostMapping("/addHistory")
    @WithRequestId
    @WebLog
    public Response<Boolean> addHistory(@RequestBody History history){
        return Response.success(userHistoryService.addHistory(history));
    }

    /**
     * 删除历史记录
     * @param history
     * @return null
     */
    @DeleteMapping("/deleteHistory")
    @WithRequestId
    @WebLog
    public Response<Boolean> deleteHistory(@RequestBody History history){
        return Response.success(userHistoryService.deleteHistory(history));
    }

    /**
     * 查询是否观看
     * @param uid
     * @param vid
     * @return
     */
    @GetMapping("/isHistory")
    @WithRequestId
    @WebLog
    public Response<Boolean> isHistory(@RequestParam("uid") Integer uid,@RequestParam("vid") Integer vid){
        return Response.success(userHistoryService.isHistory(uid,vid));
    }
}
